/*-----------------------------------------------------------------------------
 * @file   ascii.h
 * @author WLH<wanglehui8357@163.com> Copyright (C) 2021~2099.
 * @brief  ASCII Control Codes
-----------------------------------------------------------------------------*/
#ifndef _ASCII_H_
#define _ASCII_H_

/*-----------------------------------------------------------------------------
 * Pre-processor Definitions
-----------------------------------------------------------------------------*/
/* All 7-bit ASCII codes */

#define ASCII_NUL        0x00u /* Null character (^@)      */
#define ASCII_SOH        0x01u /* Start of header (^A)     */
#define ASCII_STX        0x02u /* Start of tex (^B)        */
#define ASCII_ETX        0x03u /* End of text (^C)         */
#define ASCII_EOT        0x04u /* End of transmission (^D) */
#define ASCII_ENQ        0x05u /* Enquiry (^E)             */
#define ASCII_ACK        0x06u /* Acknowledge (^F)         */
#define ASCII_BEL        0x07u /* Bell (^G)                */
#define ASCII_BS         0x08u /* Backspace (^H)           */
#define ASCII_TAB        0x09u /* Horizontal tab (^I)      */
#define ASCII_LF         0x0Au /* Line Feed (^J)           */
#define ASCII_VT         0x0Bu /* Vertical tab(^K)         */
#define ASCII_FF         0x0Cu /* Form Feed (^L)           */
#define ASCII_CR         0x0Du /* Carriage Return (^M)     */
#define ASCII_SO         0x0Eu /* Shift Out (^N)           */
#define ASCII_SI         0x0Fu /* Shift In (^O)            */
#define ASCII_DLE        0x10u /* Data link escape (^P)	  */
#define ASCII_DC1        0x11u /* Dev control 1, XON (^Q)  */
#define ASCII_DC2        0x12u /* Dev ctrl 2, block-mode flow control (^R) */
#define ASCII_DC3        0x13u /* Dev ctrl 3, XOFF (^S)    */
#define ASCII_DC4        0x14u /* Device control 4  (^T)    */
#define ASCII_NAK        0x15u /* Negative acknowledge (^U) */
#define ASCII_SYN        0x16u /* Synchronous idle (^V)     */
#define ASCII_ETB        0x17u /* End transmission block(^W)*/
#define ASCII_CAN        0x18u /* Cancel line(^X)           */
#define ASCII_EM         0x19u /* End of medium(^Y)         */
#define ASCII_SUB        0x1Au /* Substitute (^Z)           */
#define ASCII_ESC        0x1Bu /* Escape (^[)               */
#define ASCII_FS         0x1Cu /* File separator (^\)       */
#define ASCII_GS         0x1Du /* Group separator (^])      */
#define ASCII_RS         0x1Eu /* Record separator, block-mode terminator (^^) */
#define ASCII_US         0x1Fu /* Unit separator (^_)       */
#define ASCII_XON        ASCII_DC1
#define ASCII_XOFF       ASCII_DC3
#define ASCII_SPACE      0x20u /* Space ( )                 */
#define ASCII_EXCLAM     0x21u /* Exclamation mark (!)      */
#define ASCII_QUOTE      0x22u /* Quotation mark (")        */
#define ASCII_NUMBER     0x23u /* Number sign (#)           */
#define ASCII_HASH       0x23u /* Hash (#)                  */
#define ASCII_DOLLAR     0x24u /* Dollar sign ($)           */
#define ASCII_PERCENT    0x25u /* Percent sign (%)          */
#define ASCII_AMPERSAND  0x26u /* Ampersand (&)             */
#define ASCII_SQUOTE     0x27u /* Single quote (')          */
#define ASCII_APOSTROPHE 0x27u /* Apostrophe (')            */
#define ASCII_LPAREN     0x28u /* Opening parenthesis (()   */
#define ASCII_RPAREN     0x29u /* Closing parenthesis ())   */
#define ASCII_ASTERISK   0x2Au /* Asterisk (*)              */
#define ASCII_PLUS       0x2Bu /* Plus sign (+)             */
#define ASCII_COMMA      0x2Cu /* Comma (,)                 */
#define ASCII_HYPHEN     0x2Du /* Hyphen (-)                */
#define ASCII_DASH       0x2Du /* Dash (-)                  */
#define ASCII_MINUS      0x2Du /* Minus sign (-)            */
#define ASCII_PERIOD     0x2Eu /* Period (.)                */
#define ASCII_SLASH      0x2Fu /* Forward Slash (/)         */
#define ASCII_DIVIDE     0x2Fu /* Divide (/)                */

#define ASCII_0         0x30u  /* Numbers 			        */
#define ASCII_1         0x31u  /* "     " 			        */
#define ASCII_2         0x32u  /* "     " 			        */
#define ASCII_3         0x33u  /* "     " 			        */
#define ASCII_4         0x34u  /* "     " 			        */
#define ASCII_5         0x35u  /* "     " 			        */
#define ASCII_6         0x36u  /* "     " 			        */
#define ASCII_7         0x37u  /* "     " 			        */
#define ASCII_8         0x38u  /* "     " 			        */
#define ASCII_9         0x39u  /* "     " 			        */
#define ASCII_COLON     0x3Au  /* Colon (:)                 */
#define ASCII_SEMICOLON 0x3Bu  /* Semicolon (;)             */
#define ASCII_LT        0x3Cu  /* Less than (<)             */
#define ASCII_EQUAL     0x3Du  /* Equal (=)                 */
#define ASCII_GT        0x3Eu  /* Greater than (>)          */
#define ASCII_QUESTION  0x3Fu  /* Question mark (?)         */

#define ASCII_AT         0x40u /* At sign (@) */
#define ASCII_A          0x41u /* Upper case letters        */
#define ASCII_B          0x42u /* "   " "  " "     "        */
#define ASCII_C          0x43u /* "   " "  " "     "        */
#define ASCII_D          0x44u /* "   " "  " "     "        */
#define ASCII_E          0x45u /* "   " "  " "     "        */
#define ASCII_F          0x46u /* "   " "  " "     "        */
#define ASCII_G          0x47u /* "   " "  " "     "        */
#define ASCII_H          0x48u /* "   " "  " "     "        */
#define ASCII_I          0x49u /* "   " "  " "     "        */
#define ASCII_J          0x4Au /* "   " "  " "     "        */
#define ASCII_K          0x4Bu /* "   " "  " "     "        */
#define ASCII_L          0x4Cu /* "   " "  " "     "        */
#define ASCII_M          0x4Du /* "   " "  " "     "        */
#define ASCII_N          0x4Eu /* "   " "  " "     "        */
#define ASCII_O          0x4Fu /* "   " "  " "     "        */
#define ASCII_P          0x50u /* "   " "  " "     "        */
#define ASCII_Q          0x51u /* "   " "  " "     "        */
#define ASCII_R          0x52u /* "   " "  " "     "        */
#define ASCII_S          0x53u /* "   " "  " "     "        */
#define ASCII_T          0x54u /* "   " "  " "     "        */
#define ASCII_U          0x55u /* "   " "  " "     "        */
#define ASCII_V          0x56u /* "   " "  " "     "        */
#define ASCII_W          0x57u /* "   " "  " "     "        */
#define ASCII_X          0x58u /* "   " "  " "     "        */
#define ASCII_Y          0x59u /* "   " "  " "     "        */
#define ASCII_Z          0x5Au /* "   " "  " "     "        */
#define ASCII_LBRACKET   0x5Bu /* Left bracket ([)          */
#define ASCII_BACKSLASH  0x5Cu /* Back slash (\)            */
#define ASCII_RBRACKET   0x5Du /* Right bracket (])         */
#define ASCII_CARET      0x5Eu /* Caret (^)                 */
#define ASCII_CIRCUMFLEX 0x5Eu /* Circumflex (^)            */
#define ASCII_UNDERSCORE 0x5Fu /* Underscore (_)            */
#define ASCII_RSQUOTE    0x60u /* Closing single quote      */
#define ASCII_a          0x61u /* Lower case letters        */
#define ASCII_b          0x62u /* "   " "  " "     "        */
#define ASCII_c          0x63u /* "   " "  " "     "        */
#define ASCII_d          0x64u /* "   " "  " "     "        */
#define ASCII_e          0x65u /* "   " "  " "     "        */
#define ASCII_f          0x66u /* "   " "  " "     "        */
#define ASCII_g          0x67u /* "   " "  " "     "        */
#define ASCII_h          0x68u /* "   " "  " "     "        */
#define ASCII_i          0x69u /* "   " "  " "     "        */
#define ASCII_j          0x6Au /* "   " "  " "     "        */
#define ASCII_k          0x6Bu /* "   " "  " "     "        */
#define ASCII_l          0x6Cu /* "   " "  " "     "        */
#define ASCII_m          0x6Du /* "   " "  " "     "        */
#define ASCII_n          0x6Eu /* "   " "  " "     "        */
#define ASCII_o          0x6Fu /* "   " "  " "     "        */
#define ASCII_p          0x70u /* "   " "  " "     "        */
#define ASCII_q          0x71u /* "   " "  " "     "        */
#define ASCII_r          0x72u /* "   " "  " "     "        */
#define ASCII_s          0x73u /* "   " "  " "     "        */
#define ASCII_t          0x74u /* "   " "  " "     "        */
#define ASCII_u          0x75u /* "   " "  " "     "        */
#define ASCII_v          0x76u /* "   " "  " "     "        */
#define ASCII_w          0x77u /* "   " "  " "     "        */
#define ASCII_x          0x78u /* "   " "  " "     "        */
#define ASCII_y          0x79u /* "   " "  " "     "        */
#define ASCII_z          0x7Au /* "   " "  " "     "        */
#define ASCII_LBRACE     0x7Bu /* Left brace ({)            */
#define ASCII_VERTBAR    0x7Cu /* Vertical bar (|)          */
#define ASCII_PIPE       0x7Cu /* Pipe (|)                  */
#define ASCII_RBRACE     0x7Du /* Right brace (})           */
#define ASCII_TILDE      0x7Eu /* Tilde (~)                 */
#define ASCII_DEL        0x7Fu /* Delete (rubout)           */

/*-----------------------------------------------------------------------------
 * Utils Macro define
-----------------------------------------------------------------------------*/
#define IS_UPPER(c)   (((c) >= ASCII_A) && ((c) <= ASCII_Z))
#define IS_LOWER(c)   (((c) >= ASCII_a) && ((c) <= ASCII_z))
#define IS_DIGITAL(c) (((c) >= ASCII_0) && ((c) <= ASCII_9))
#define TO_UPPER(c)   ((IS_LOWER(c)) ? ((c) - (ASCII_a - ASCII_A)) : (c))
#define TO_LOWER(c)   ((IS_UPPER(c)) ? ((c) + (ASCII_a - ASCII_A)) : (c))

#define CHAR_IS_NUM(x) ((x) >= '0' && (x) <= '9')
#define CHAR_TO_NUM(x) ((x) - '0')

#define CHAR_IS_HEX_NUM(x) (((x) >= '0' && (x) <= '9') || ((x) >= 'a' && (x) <= 'f') || ((x) >= 'A' && (x) <= 'F'))
#define CHAR_HEX_TO_NUM(x) (((x) >= '0' && (x) <= '9') ? ((x) - '0') : (((x) >= 'a' && (x) <= 'f') ? ((x) - 'a' + 10) : (((x) >= 'A' && (x) <= 'F') ? ((x) - 'A' + 10) : 0)))
#define IS_VALID_ASCII(x)  (((x) >= 32 && (x) <= 126) || (x) == '\r' || (x) == '\n')

#endif //~_ASCII_H_
